package com.erin724.erinsleep;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
import android.widget.TimePicker;

public class SetTimeActivity extends Activity {
	int hour;
	int minute;
	TimePicker timePicker1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_set_time);
		Intent intent = getIntent();
		TextView tv = (TextView) findViewById(R.id.SetTimeName);
		int requestCode = intent.getIntExtra(MainActivity.REQCODE, 0);
		if(requestCode == MainActivity.CORE1_SLEEPTIME_PRESS) {
			tv.setText("Core 1 Sleeptime");
		}
		else if (requestCode == MainActivity.CORE1_WAKETIME_PRESS) {
			tv.setText("Core 1 Waketime");
		}
		else if (requestCode == MainActivity.NAP1_SLEEPTIME_PRESS) {
			tv.setText("Nap 1 Sleeptime");
		}
		else if (requestCode == MainActivity.NAP1_WAKETIME_PRESS) {
			tv.setText("Nap 1 Waketime");
		}
		else if (requestCode == MainActivity.NAP2_SLEEPTIME_PRESS) {
			tv.setText("Nap 2 Sleeptime");
		}
		else if (requestCode == MainActivity.NAP2_WAKETIME_PRESS) {
			tv.setText("Nap 2 Waketime");
		}
		else if (requestCode == MainActivity.NAP3_SLEEPTIME_PRESS) {
			tv.setText("Nap 3 Sleeptime");
		}
		else if (requestCode == MainActivity.NAP3_WAKETIME_PRESS) {
			tv.setText("Nap 3 Waketime");
		}
		hour = intent.getIntExtra(MainActivity.HOUR, 0);
		minute = intent.getIntExtra(MainActivity.MINUTE, 0);
		timePicker1 = (TimePicker) findViewById(R.id.timePicker1);
		timePicker1.setIs24HourView(true);
		timePicker1.setCurrentHour(hour);
		timePicker1.setCurrentMinute(minute);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.set_time, menu);
		return true;
	}
	
	public void setAlarmTime(View v) {
		hour = timePicker1.getCurrentHour();
		minute = timePicker1.getCurrentMinute();
		Intent intent = new Intent();
		intent.putExtra(MainActivity.HOUR, hour);
		intent.putExtra(MainActivity.MINUTE, minute);
		setResult(RESULT_OK, intent);
		finish();
	}

}
